#include <mesh/transform.h>
#include <mesh/mesh.h>
#include <app/ameTypes.h>

Transform::Transform ( ame::vec3 position, ame::vec3 rotation ) {
    this -> position = position;
    this -> rotation = rotation;
    this -> scale = ame::vec3 (1, 1, 1);
}

Transform::Transform () {
    position = ame::vec3 (0, 0, 0);
    rotation = ame::vec3 (0, 0, 0);
    scale = ame::vec3 (1, 1, 1);
}


void Transform::setMesh ( Mesh* mesh ) {
    currentMesh = mesh;
}


void Transform::setX ( double x ) {
    position.x = x;
}

void Transform::setY ( double y ) {
    position.y = y;
}

void Transform::setZ ( double z ) {
    position.z = z;
}


double Transform::returnX () {
    return position.x;
}

double Transform::returnY () {
    return position.y;
}

double Transform::returnZ () {
    return position.z;
}


void Transform::setPosition ( ame::vec3 axis ) {
    position.x = axis.x;
    position.y = axis.y;
    position.z = axis.z;
}

void Transform::translate ( ame::vec3 direction ) {
    position.x += direction.x;
    position.y += direction.y;
    position.z += direction.z;
}


void Transform::setRotation ( ame::vec3 deg ) {
    rotation = deg;
}
void Transform::rotate ( ame::vec3 deg ) {
    rotation.x += deg.x;
    rotation.y += deg.y;
    rotation.z += deg.z;
}

void Transform::updateMesh () {
    //transform
    for ( unsigned int i = 0; i < currentMesh -> viewPoints.size(); i++ ) {
        currentMesh -> viewPoints[i].x = currentMesh -> points [i].x + position.x;
        currentMesh -> viewPoints[i].y = currentMesh -> points [i].y + position.y;
        currentMesh -> viewPoints[i].z = currentMesh -> points [i].z + position.z;
    }
    
    //rotate
    currentMesh -> rotate ( rotation.x, aX );
    currentMesh -> rotate ( rotation.y, aY );
    currentMesh -> rotate ( rotation.z, aZ );
    
    //scale
}
